package com.socodethis.spaceex;

import java.util.Random;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.socodethis.spaceex.math.cPoint;
import com.socodethis.spaceex.math.cRect;

public class enemyClass extends charClass {

	//This tells us if the enemy sees the player
	private cPoint lastMoved;
	private Random random = new Random(System.nanoTime());
	private int sightRange = 3;
	private boolean stationary;
	private AttackLoader enemyAttack;
	private int attackCounter;
	public enemyClass(spriteAnimate movement, dungeonGenerator map, AttackLoader enemyAttack,boolean stationary) {
		super(movement, map);
		lastMoved = new cPoint(this.getPosition());
		this.stationary = stationary;
		this.enemyAttack = enemyAttack; 
		attackCounter = 0;
	}
	//This sets the enemy movement based on where the player is
	public void setMovement(cPoint playerPos){
		//Right now, just moves enemy towards player
		if(!stationary){
			moveChar(playerPos);
			lastMoved = new cPoint(playerPos);
		}
	}
	public void getAlerted(){
		//If the enemy is moving, he is this color
		if(this.movement.isMoving()){
			this.sprite.setColor(new Color(1,0,1,1));
		}else{
			//If not, he is this color
			//this.sprite.setColor(new Color(.5f,1f,.5f,1));
		}
	}
	public void runUpdate(float currentTime){
		this.setSprite(currentTime);
		getAlerted();
	}
	public float getSightRange(){
		return sightRange;
	}
	public cRect getSightBox(){
		return new cRect(getPosition().getX()-sightRange,getPosition().getY()-sightRange,2*sightRange,2*sightRange);
	}
	public AttackLoader getEnemyAttack(){
		return enemyAttack;
	}
	public void addCycle(){
		attackCounter++;
	}
	public boolean getCycles(){
		if(attackCounter>=enemyAttack.aSpeed){
			attackCounter=0;
			return true;
		}
		return false;
	}
}
